# encoding=utf-8
import os
import zipfile


class DirPackage:
    """文件夹打包工具类，
        可能会封装好几种类型，所以建立类
    """

    @staticmethod
    def pack_zip(from_path, to_path):
        """打包指定路径到某目录下面
            :param from_path: 打包路径
            :param to_path: .zip结尾的文件存放位置
        """
        z = zipfile.ZipFile(to_path, 'w', zipfile.ZIP_DEFLATED)
        for path, dirnames, filenames in os.walk(from_path):
            fpath = path.replace(from_path, '')
            for filename in filenames:
                encode_name = filename.encode('utf-8').decode('utf-8')
                z.write(os.path.join(path, filename),
                        os.path.join(fpath, encode_name))
        z.close()
        (file_path, file_name) = os.path.split(to_path)
        return file_name
